<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/base.js"></script>
    <script src="js/md5.js"></script>
</head>
<body>
    <input id="signInName" type="text"/><br>
    <input id="password" type="password"/><br>
    <button onclick="onSignInClick();">登陆</button>
    <br>
    <button onclick="onTestClick();">登陆成功以后，再次请求服务器</button>
    <script>
        function onTestClick(){
            let url="http://localhost:9001/qf/user/test";
            let method="get";
            $.rest(method,url,null,function(r){
                if(r.ok){
                    alert(JSON.stringify(r));
                }
            });
        }
        function onSignInClick(){
            let signInName=document.getElementById("signInName").value;
            let password=document.getElementById("password").value;
            password=md5(password).toUpperCase();
            let url="http://localhost:9001/qf/user/signIn";
            let requestJson={};
            requestJson.signInName=signInName;
            requestJson.password=password;
            $.rest("post",url,requestJson,function(r){
                if(r.ok){
                    let token=r.result.token;
                    let id=r.result.user.id;
                    let username=r.result.user.username;
                    let nickname=r.result.user.nickname;
                    let gender=r.result.user.gender;
                    let telephone=r.result.user.telephone;
                    let email=r.result.user.email;
                    let iconLink=r.result.user.iconLink;
                    //使用前端的数据存储
                    localStorage.setItem("token",token);
                    localStorage.setItem("id",id);
                    localStorage.setItem("username",username);
                    localStorage.setItem("nickname",nickname);
                    localStorage.setItem("gender",gender);
                    localStorage.setItem("telephone",telephone);
                    localStorage.setItem("email",email);
                    localStorage.setItem("iconLink",iconLink);
                    alert("登陆成功");
                }else{
                    alert(r.msg);
                }
            });
        }
    </script>
</body>
</html>